#官方镜像
FROM elasticsearch:8.5.2

COPY ./file/* /usr/local/src/

VOLUME /usr/share/elasticsearch/certs

##添加ik分词器  https://github.com/medcl/elasticsearch-analysis-ik
RUN unzip /usr/local/src/elasticsearch-analysis-ik-8.5.2.zip -d /usr/share/elasticsearch/plugins/ik
#RUN chmod 777 /usr/share/elasticsearch/plugins/ik -R

#生成ca，密码可自己配置
RUN bin/elasticsearch-certutil ca --out certs/elastic-stack-ca.p12 --pass 123456

#生成证书，密码可自己配置
RUN bin/elasticsearch-certutil cert --ca certs/elastic-stack-ca.p12 --ca-pass 123456 --out certs/elastic-certificates.p12 --pass 123456

#创建keystore
RUN bin/elasticsearch-keystore create

#将密码添加至keystore
RUN sh -c '/bin/echo -e "123456" | sh bin/elasticsearch-keystore add xpack.security.transport.ssl.keystore.secure_password'
RUN sh -c '/bin/echo -e "123456" | sh bin/elasticsearch-keystore add xpack.security.transport.ssl.truststore.secure_password'
RUN sh -c '/bin/echo -e "123456" | sh bin/elasticsearch-keystore add xpack.security.http.ssl.keystore.secure_password'
RUN sh -c '/bin/echo -e "123456" | sh bin/elasticsearch-keystore add xpack.security.http.ssl.truststore.secure_password'

#文件赋权限
#RUN chmod 777 /usr/share/elasticsearch/config/elastic-certificates.p12
#RUN chmod 777 /usr/share/elasticsearch/config/elastic-stack-ca.p12
